package com.yidi.monitor;

import com.yidi.system.domain.SysLogininfor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.yidi.common.annotation.Log;
import com.yidi.common.core.controller.BaseController;
import com.yidi.common.core.domain.AjaxResult;
import com.yidi.common.core.page.TableDataInfo;
import com.yidi.common.enums.BusinessType;
import com.yidi.common.utils.poi.ExcelUtil;
import com.yidi.system.service.SysLogininforService;

/**
 * @author ：Xn
 * @ClassName: SysLogininforController
 * @date ：2021-10-19 15:06
 * @describe ：系统访问记录
 */
@RestController
@RequestMapping("/monitor/logininfor")
public class SysLogininforController extends BaseController
{
    @Autowired
    private SysLogininforService logininforService;

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLogininfor logininfor, @RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize)
    {
        Page<SysLogininfor> findByPage = logininforService.findByPage(pageNum, pageSize, logininfor);
        return getDataTable(findByPage);
    }

    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')")
    @GetMapping("/export")
    public AjaxResult export(SysLogininfor logininfor)
    {
        Page<SysLogininfor> findByPage = logininforService.findByPage(0, Integer.MAX_VALUE, logininfor);
        ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
        return util.exportExcel(findByPage.getContent(), "登录日志");
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds)
    {
        logininforService.deleteLogininforByIds(infoIds);
        return success();
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean()
    {
        logininforService.cleanLogininfor();
        return AjaxResult.success();
    }
}
